001 /* EVolve - an Extensible Software Visualization Framework
002 * Copyright (C) 2001-2002 Qin Wang
003 *
004 * This library is free software; you can redistribute it and/or
005 * modify it under the terms of the GNU Library General Public
006 * License as published by the Free Software Foundation; either
007 * version 2 of the License, or (at your option) any later version.
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Library General Public License for more details.
013 *
014 * You should have received a copy of the GNU Library General Public
015 * License along with this library; if not, write to the
016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017 * Boston, MA 02111-1307, USA.
018 */
019
020 /*
021 * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/
022 */
023
024 package EVolve.data;
025
026
027 public class DataFilter implements Cloneable{
028 private String name; // name of the filter
029 private int fieldIndex; // index of the field that the filter needs to get
030 private ReferenceLink referenceLink; // reference link
031 private String description; // description of the filter
032 private String[] property; // property names of viz dimension
033
034 /**
035 * Creates a data filter.
036 *
037 * @param name name of the filter
038 * @param fieldIndex index of the field that the filter needs to get
039 * @param referenceLink reference link, null if the field is a value
040 * @param descri description of the filter
041 */
042 public DataFilter(String name, int fieldIndex, ReferenceLink referenceLink, String description, String[] property) {
043 this.name = name;
044 this.fieldIndex = fieldIndex;
045 this.referenceLink = referenceLink;
046 this.description = description;
047 this.property = property;
048 }
049
050 /**
051 * Gets the name of the filter.
052 *
053 * @return name of the filter
054 */
055 public String getName() {
056 return name;
057 }
058
059 /**
060 * Gets the type of the refenrence link.
061 *
062 * @return type of the refenrence link, -1 if the field is a value
063 */
064 public int getTargetType() {
065 if (referenceLink == null) {
066 return -1;
067 } else {
068 return referenceLink.getTargetType();
069 }
070 }
071
072 /**
073 * Gets the data from the element.
074 *
075 * @return id of the entity if the field is a reference, or the value if the field is a value
076 */
077 public long getData(Element element) {
078 if (referenceLink == null) {
079 return element.getField()[fieldIndex];
080 } else {
081 return referenceLink.getTarget(element.getField()[fieldIndex]);
082 }
083 }
084
085 /**
086 * Gets the description of the filter.
087 *
088 * @return description of the filter
089 */
090 public String getDescription() {
091 return description;
092 }
093
094 public String[] getProperty() {
095 return property;
096 }
097
098 public Object clone() {
099 DataFilter o = null;
100 try {
101 o = (DataFilter)super.clone();
102 } catch (CloneNotSupportedException e) {
103 e.printStackTrace();
104 return null;
105 }
106 o.name = name;
107 o.referenceLink = (referenceLink == null) ? null : (ReferenceLink)referenceLink.clone();
108 return o;
109 }
110 }